package org.example;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Map_Demo1 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("超人","雅威");
        map.put("炒人","哈哥");
        System.out.println(map);
//键找值遍历方法
        Set<String>s= map.keySet();
       /* for (String st : s) {
            //System.out.println(st);
            String value=map.get(st);
            System.out.println(st+"="+value);
        }*/
        //迭代器
        Iterator<String> it=map.keySet().iterator();
        while(it.hasNext()){
            String key=it.next();
            String value=map.get(key);
            System.out.println(key+"="+value);
        }
        //匿名内部类
        map.forEach(new BiConsumer<String,String>() {
            @Override
            public void accept(String k, String v) {
                System.out.println(k+"="+v);
            }
        });
        //lamda表达式进行遍历
        map.forEach((k,v)-> System.out.println(k+"="+v));
    }
}
